package com.xxhui.listviewdemo.View;

import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.widget.ListView;

/**
 * Created by hui on 2016/7/18.
 */
public class FlexibleListView extends ListView {

    private static final String TAG = "FlexibleListView" ;
    private static int flexibleDistance=50 ;//弹性listview的弹出距离

    public FlexibleListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initParam(context);
    }

    public FlexibleListView(Context context) {
        super(context);
        initParam(context);
    }

    public void initParam(Context context){
        DisplayMetrics metrics = context.getResources().getDisplayMetrics();
        float density =metrics.density;//密度独立像素单元比例因子
        //int screenHeight = metrics.heightPixels;
        //flexibleDistance = screenHeight;
        Log.i(TAG, "initParam: 密度独立像素单元比例因子:"+density);
        flexibleDistance = (int) (density*flexibleDistance);
    }

    @Override
    protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) {
        return super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, flexibleDistance, isTouchEvent);
    }
}
